using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace LMSData
{
    /// <summary>
    /// Controller class for CourseGroupMap
    /// </summary>
    [System.ComponentModel.DataObject]
    public partial class CourseGroupMapController
    {
        // Preload our schema..
        CourseGroupMap thisSchemaLoad = new CourseGroupMap();
        private string userName = string.Empty;
        protected string UserName
        {
            get
            {
				if (userName.Length == 0) 
				{
    				if (System.Web.HttpContext.Current != null)
    				{
						userName=System.Web.HttpContext.Current.User.Identity.Name;
					}

					else
					{
						userName=System.Threading.Thread.CurrentPrincipal.Identity.Name;
					}

				}

				return userName;
            }

        }

        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public CourseGroupMapCollection FetchAll()
        {
            CourseGroupMapCollection coll = new CourseGroupMapCollection();
            Query qry = new Query(CourseGroupMap.Schema);
            coll.LoadAndCloseReader(qry.ExecuteReader());
            return coll;
        }

        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public CourseGroupMapCollection FetchByID(object CourseID)
        {
            CourseGroupMapCollection coll = new CourseGroupMapCollection().Where("CourseID", CourseID).Load();
            return coll;
        }

		
		[DataObjectMethod(DataObjectMethodType.Select, false)]
        public CourseGroupMapCollection FetchByQuery(Query qry)
        {
            CourseGroupMapCollection coll = new CourseGroupMapCollection();
            coll.LoadAndCloseReader(qry.ExecuteReader()); 
            return coll;
        }

        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public bool Delete(object CourseID)
        {
            return (CourseGroupMap.Delete(CourseID) == 1);
        }

        [DataObjectMethod(DataObjectMethodType.Delete, false)]
        public bool Destroy(object CourseID)
        {
            return (CourseGroupMap.Destroy(CourseID) == 1);
        }

        
        
        
        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public bool Delete(int CourseID,int GroupID)
        {
            Query qry = new Query(CourseGroupMap.Schema);
            qry.QueryType = QueryType.Delete;
            qry.AddWhere("CourseID", CourseID).AND("GroupID", GroupID);
            qry.Execute();
            return (true);
        }
        
       
    	
    	
	    /// <summary>
	    /// Inserts a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Insert, true)]
	    public void Insert(int CourseID,int GroupID)
	    {
		    CourseGroupMap item = new CourseGroupMap();
		    
            item.CourseID = CourseID;
            
            item.GroupID = GroupID;
            
	    
		    item.Save(UserName);
	    }

    	
	    /// <summary>
	    /// Updates a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
	    public void Update(int CourseID,int GroupID)
	    {
		    CourseGroupMap item = new CourseGroupMap();
		    
				item.CourseID = CourseID;
				
				item.GroupID = GroupID;
				
		    item.MarkOld();
		    item.Save(UserName);
	    }

    }

}

